/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.*

/**
 * ProcessDefinitions
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface ProcessDefinitionsApi {


    /**
     * List of process definitions
     */
    @GetMapping("/repository/process-definitions")
    fun listProcessDefinitions(
        @RequestParam(name = "version", required = false) version: Int?,
        @RequestParam(name = "name", required = false) name: String?,
        @RequestParam(name = "nameLike", required = false) nameLike: String?,
        @RequestParam(name = "nameLikeIgnoreCase", required = false) nameLikeIgnoreCase: String?,
        @RequestParam(name = "key", required = false) key: String?,
        @RequestParam(name = "keyLike", required = false) keyLike: String?,
        @RequestParam(name = "resourceName", required = false) resourceName: String?,
        @RequestParam(name = "resourceNameLike", required = false) resourceNameLike: String?,
        @RequestParam(name = "category", required = false) category: String?,
        @RequestParam(name = "categoryLike", required = false) categoryLike: String?,
        @RequestParam(name = "categoryNotEquals", required = false) categoryNotEquals: String?,
        @RequestParam(name = "deploymentId", required = false) deploymentId: String?,
        @RequestParam(name = "startableByUser", required = false) startableByUser: String?,
        @RequestParam(name = "latest", required = false) latest: Boolean?,
        @RequestParam(name = "suspended", required = false) suspended: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<ProcessDefinitionResponse>>

    /**
     * Get a process definition
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}")
    fun getProcessDefinition(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<ProcessDefinitionResponse>

    /**
     * Execute actions for a process definition (Update category, Suspend or Activate)
     */
    @PutMapping("/repository/process-definitions/{processDefinitionId}")
    fun executeProcessDefinitionAction(
        @PathVariable("processDefinitionId") processDefinitionId: String,
        @RequestBody(required = true) body: ProcessDefinitionActionRequest
    ): R<ProcessDefinitionResponse>

    /**
     * Batch migrate all instances of process definition
     */
    @PostMapping("/repository/process-definitions/{processDefinitionId}/batch-migrate")
    fun batchMigrateInstancesOfProcessDefinition(
        @PathVariable("processDefinitionId") processDefinitionId: String,
        @RequestBody(required = false) body: String?
    ): R<Any>

    /**
     * List decision tables for a process-definition
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/decision-tables")
    fun listProcessDefinitionDecisionTables(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>

    /**
     * List decisions for a process-definition
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/decisions")
    fun listProcessDefinitionDecisions(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>

    /**
     * List form definitions for a process-definition
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/form-definitions")
    fun listProcessDefinitionFormDefinitions(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>

    /**
     * List candidate starters for a process-definition
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/identitylinks")
    fun listProcessDefinitionIdentityLinks(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>

    /**
     * It is possible to add either a user or a group.
     */
    @PostMapping("/repository/process-definitions/{processDefinitionId}/identitylinks")
    fun createIdentityLink(
        @PathVariable("processDefinitionId") processDefinitionId: String,
        @RequestBody(required = false) body: RestIdentityLink?
    ): R<RestIdentityLink>

    /**
     * Get a candidate starter from a process definition
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/identitylinks/{family}/{identityId}")
    fun getIdentityLink(
        @PathVariable("processDefinitionId") processDefinitionId: String,
        @PathVariable("family") family: String,
        @PathVariable("identityId") identityId: String
    ): R<RestIdentityLink>

    /**
     * Delete a candidate starter from a process definition
     */
    @DeleteMapping("/repository/process-definitions/{processDefinitionId}/identitylinks/{family}/{identityId}")
    fun deleteIdentityLink(
        @PathVariable("processDefinitionId") processDefinitionId: String,
        @PathVariable("family") family: String,
        @PathVariable("identityId") identityId: String
    ): R<Any>

    /**
     * Get a process definition image
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/image")
    fun getModelResource(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>

    /**
     * Migrate all instances of process definition
     */
    @PostMapping("/repository/process-definitions/{processDefinitionId}/migrate")
    fun migrateInstancesOfProcessDefinition(
        @PathVariable("processDefinitionId") processDefinitionId: String,
        @RequestBody(required = false) body: String?
    ): R<Any>

    /**
     * Get a process definition BPMN model
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/model")
    fun getBpmnModelResource(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<BpmnModel>

    /**
     * Get a process definition resource content
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/resourcedata")
    fun getProcessDefinitionResource(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>

    /**
     * Get a process definition start form
     */
    @GetMapping("/repository/process-definitions/{processDefinitionId}/start-form")
    fun getProcessDefinitionStartForm(
        @PathVariable("processDefinitionId") processDefinitionId: String
    ): R<Any>
}